package com.yj.jason.jsondemo;

import android.Manifest;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.yj.jason.moudlelibrary.activity.BaseSkinActivity;
import com.yj.jason.moudlelibrary.skin.SkinManager;
import com.yj.jason.moudlelibrary.skin.SkinResource;
import com.yj.jason.moudlelibrary.view.DefaultNavigation;

import java.io.File;

import io.reactivex.functions.Consumer;

public class SkinActivity extends BaseSkinActivity implements View.OnClickListener{

    private Button btn_change;
    private Button btn_restore,btn_jump;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_skin);
        btn_change=(Button)findViewById(R.id.btn_change);
        btn_restore=(Button)findViewById(R.id.btn_restore);
        btn_jump=(Button)findViewById(R.id.btn_jump);

        DefaultNavigation navigationBar = new DefaultNavigation.Builder(this)
                .setLeftIcon(R.mipmap.ic_launcher).setTitle("投稿").create();


        btn_change.setOnClickListener(this);
        btn_restore.setOnClickListener(this);
        btn_jump.setOnClickListener(this);



        requestRxPermission();



      //  LayoutInflaterCompat.setFactory2();




    }


    private void requestRxPermission(){
        RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance

        rxPermissions
                .requestEach(
                        Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Permission>() {
                    @Override
                    public void accept(Permission permission) throws Exception {
                        if (permission.granted) {
                           // LogUtil.i("testRxPermission CallBack onPermissionsGranted() : "+permission.name+
                           //         " request granted , to do something...");
                            //todo somthing
                        }
                        else if (permission.shouldShowRequestPermissionRationale) {
                           // LogUtil.e("testRxPermission CallBack onPermissionsDenied() : " + permission.name + "request denied");
                           // ToastUtil.showShort(instance, "拒绝权限，等待下次询问哦");
                            //todo request permission again
                        }
                        else {
                           // LogUtil.e("testRxPermission CallBack onPermissionsDenied() : this " + permission.name + " is denied " +
                            //        "and never ask again");
                          //  ToastUtil.showShort(instance, "拒绝权限，不再弹出询问框，请前往APP应用设置中打开此权限");
                            //todo nothing
                        }
                    }
                });

    }



    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_change:
              //  startActivity(new Intent(this,BannerViewActivity.class));
              /*  String path= Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+"red.skin";

                SkinManager.getInstance().loakSkin(path);*/

              btn_change.setText("开启了线程 再试试5555555");

                break;
            case R.id.btn_restore:

                btn_restore.setText("开启了线程  再试试55555555");

               // SkinManager.getInstance().retoreDefault();
               // startActivity(new Intent(this,SkinActivity.class));
                break;
            case R.id.btn_jump:
              //  Toast.makeText(this,2/0+"",Toast.LENGTH_SHORT).show();
                Toast.makeText(this,"好烦山东发   再试试",Toast.LENGTH_SHORT).show();
                btn_jump.setText("好烦山东发  再试试");


               // startActivity(new Intent(this,SkinActivity.class));
                break;
        }

    }

    @Override
    public void changeSkin(SkinResource skinResource) {
        super.changeSkin(skinResource);

    }
}
